//微信
var id;
if($.cookie("MYID")){id=$.cookie("MYID")};
var returnurl=encodeURIComponent("https://www.pulu.com/weixin/sendexpg.html"); //同意后跳转页面
$(document).ready(function(){
    if(is_weixn()){
        if($.cookie("wxopenid")){
            //===============================================================================
            //从登录页返回有openid没有id
            if(!$.cookie("MYID")){location.href="https://www.pulu.com/weixin/login.html"}
            //===============================================================================
        }
        else{
            //先微信验证获取openid 如果已经授权过了 直接页面截取openid 然后发送请求获取 用户的ID
            var reg=new RegExp("code=[a-zA-Z0-9]*");
            if(window.location.href.match(reg)){
                var code=window.location.href.match(reg);
                $.ajax({
                    type:"GET",
                    url:"GetOpenId.ashx?"+code,
                    async: false,
                    success:function(data){
                        console.log(data);
                        var dat=data;
                        $.cookie("wxod",dat);
                        //发请求获取用户的id
                        $.ajax({
                            type:"GET",
                            url:getwxopenidurl+dat,
                            success:function(d){
                                //如果没有用户id 则证明用户是第一次登陆 保存openid跳转至登录页面
                                if(!d.Data){
                                    //微信跳转进来的
                                    if(!$.cookie("MYID")){
                                        $.cookie("wxopenid",dat);
                                        location.href="https://www.pulu.com/weixin/login.html"
                                    }
                                    //退出登录的
                                }else if(d.Data&&d.Data.userId.length>0){
                                    $.cookie("wxopenid",d.Data.openId);
                                    $.cookie("MYID",d.Data.userId);
                                    //id=d.Data.userId;
                                    location.href="https://www.pulu.com/weixin/sendexpg.html"

                                }
                            }
                        })
                    }
                })
            }
            else{
                location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx658c34793ecfd9f9&redirect_uri="+returnurl+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
            }
        }
    }
    //else{
    //    allftn();
    //}
});

$("#sendimginfo div").css("marginTop",(window.innerHeight-83)/2);
$("#sendinfo div").css("marginTop",(window.innerHeight-83)/2);
var hyischoiced=[];//已经选择的行业document.body.clientWidth
var xqischoiced=[];//已经选择的兴趣
var xqchoicenum=0;
var choicenum=0;
var question = {};
question.score =0;//分数
var qtypenum =3;
$(".queskind").html("");

document.querySelector(".page_title.unified").innerHTML="我也说说";
$("#keywordinput").attr("placeholder","必填，且在文中出现过");
$("#contentword").attr("placeholder","最近的电影推荐，饭店推荐，游玩的地方，好看的书...\n上班交通经验，推荐的工作午餐...\n吃亏经历，新奇事,划算事...");
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////获取列表数据///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//原window.load内容
question.qtype=3;//2问题3经验
question.isstrangersee = 1;//陌生人是否可见  0否1是
question.ishidename = 0;//是否匿名发布  0否1是
atmeIsHideName=0;//默认不匿名
question.iswhocansee = 0;//是否是部分可见 0否1是 和 isforbidwhosee互斥
var somecanseeclick=0;//判断点击事件
question.isforbidwhosee = 0;//是否是不给谁看  0否1是 和 iswhocansee互斥
var scnotsee=0;//判断点击事件
var pwhocanseelist = [];//可见人的id列表
var pforbidseelist = [];//不可见人的id列表
var plist = [];//能看此图片的人的列表
var imgresult;
var userallmoney=0;
var persons = [];  //招唤的人
var imgfriend=0; //判断当前朋友列表对应图片还是问题  对应图片
var sendfriend=0;//判断当前朋友列表对应图片还是问题  对应问题
var imgcanseename=[]; //可以看图片人
var callfrienfname=[];
var labeldata;//保存标签组
var woseetype="";//用来判断当前标签组是部分可见 还是提醒谁看
//----------------------------------------------------------------------------------------------------------------------
//动态生成nav列表
$.ajax({
    type:"get",
    url:"https://www.pulu.com/webapi/api/Pulu_fltype/Getpulu_fltype",
    datatype:"json",
    success:function(d){
        $.each(d.Data,function(n,j){
            switch(j.id){
                case 1: $("#chikui").next().html(j.name);break;//吃亏
                case 2: $("#huasuan").next().html(j.name);break;//划算
                case 3: $("#xinqi").next().html(j.name);break;//新奇
                case 4: $("#qita").next().html(j.name);break;//其他
                case 5: $("#tuijiandy").next().html(j.name);break;//电影
                case 6: $("#tuijianfd").next().html(j.name);break;//饭店
                case 7: $("#youwan").next().html(j.name);break;//游玩
                case 8: $("#shu").next().html(j.name);break;//书
                case 22: $("#nearlyexp").next().html(j.name);break;//附近
                case 23: $("#rensheng").next().html(j.name);break;//人生
            }
        });
    }
});
//有没有传入经验ID 召唤用户，关键词数据$.cookie("expkeyword")中保存经验id
if($.cookie("expkeyword")){
    $.cookie("sendque")=="question"?$("#samekeyword").css("display","none"):$("#samekeyword").css("display","block");
    $("#callfriend").css("display","none");
    var sendexptype=3;
    if(($.cookie("sendque")=="question")||/sendque=question/.test(location.href)){
        sendexptype=2;
    }
    $.ajax({
        type:"get",
        datatype:"json",
        url:hexpnoteurl+$.cookie("expkeyword")+"&qtype="+sendexptype,
        success:function(d){
            $("#keywordinput").val(d.Data.keywords);
            if(d.Data.payuserids){
                $.each(d.Data.payuserids,function(i,e){
                    if(e!=id){
                        persons.push(e);
                    }
                });
            }
        }
    })
}
//发布问题获取账户余额===============================
$.ajax({
    type:"get",
    url:lastscoreurl+id,
    success:function(d){
        userallmoney=parseInt(d.Data)/100;
        //console.log(userallmoney);
    }
});
//发问题
if($.cookie("sendque")=="question"){
    question.qtype=2;
    $("#choiceque").attr("class","active");
    $("#choiceexp").attr("class","");
    $("#contentword").attr("placeholder","有什么烦恼解不开？\n有什么困惑想不通？\n有什么好奇的事？");
    $("#sendtype").css("display","none");
    $("#gaojilistbox .sendquestionpage:first-child").css("display","none");
}
//切换类型
$("#choiceque").click(function(){
    $(".changetype>div").toggleClass("active");
    question.qtype=2;
    //console.log(question.qtype+"问题：关");
    $("#gaojilistbox .sendquestionpage:first-child").css("display","none");
    $("#sendtype").css("display","none");
    $("#contentword").attr("placeholder","有什么烦恼解不开？\n有什么困惑想不通？\n有什么好奇的事？");
})
$("#choiceexp").click(function(){
    $(".changetype>div").toggleClass("active");
    question.qtype=3;
    //console.log(question.qtype+"经验：开");
    $("#gaojilistbox .sendquestionpage:first-child").css("display","block");
    $("#sendtype").css("display","block");
    $("#contentword").attr("placeholder","最近的电影推荐，饭店推荐，游玩的地方，好看的书...\n上班交通经验，推荐的工作午餐...\n吃亏经历，新奇事,划算事...")
})
//$(".changetype>div").click(function(){
//    $(".changetype>div").toggleClass("active");
//    //question.qtype=question.qtype==2?3:2;
//    if(question.qtype==3){
//        question.qtype=2;
//
//        console.log(question.qtype+"问题：关");
//        $("#gaojilistbox .sendquestionpage:first-child").css("display","none");
//        $("#sendtype").css("display","none");
//        $("#contentword").attr("placeholder","描述您的问题...");
//    }
//    if(question.qtype==2){
//        question.qtype=3;
//        console.log(question.qtype+"经验：开");
//        $("#gaojilistbox .sendquestionpage:first-child").css("display","block");
//        $("#sendtype").css("display","block");
//        $("#contentword").attr("placeholder","划算的事，吃亏的事，新奇的事，电影，饭店，游玩，书...想想有什么可以分享的(＾－＾)V")
//    }
//});
//监听输入框数字（纯一位数字）
$("#unitprice").bind('input propertychange',function(){
    //包含其他字符
    if(!/^[0-9]+$/.test($("#unitprice").val())){
        $("#unitprice").val($("#unitprice").val().replace(/[^0-9]/ig,""));
        if($("#unitprice").val().length>3){
            $("#unitprice").val(($("#unitprice").val()).substr(0,3));
        }
    }
    if($("#unitprice").val()){
        //var a=$("#unitprice").val().toString();
        //var b= a.substr(0,1);
        $("#unitprice").val(parseFloat($("#unitprice").val()));
        if($("#unitprice").val().length>3){
            $("#unitprice").val(($("#unitprice").val()).substr(0,3));
        }
    }
});
$("#allday").bind('input propertychange',function(){
    //包含其他字符
    if(!/^[0-9]+$/.test($("#allday").val())){
        $("#allday").val($("#allday").val().replace(/[^0-9]/ig,""));
        if($("#allday").val().length>3){
            $("#allday").val(($("#allday").val()).substr(0,3));
        }
    }
    if($("#allday").val()){
        //var a=$("#allday").val().toString();
        //var b= a.substr(0,1);
        $("#allday").val(parseFloat($("#allday").val()));
        if($("#allday").val().length>3){
            $("#allday").val(($("#allday").val()).substr(0,3));
        }
    }
});
$("#allprice").bind('input propertychange',function(){
    //包含其他字符
    if(!/^[0-9]+$/.test($("#allprice").val())){
        $("#allprice").val($("#allprice").val().replace(/[^0-9]/ig,""));
        if($("#allprice").val().length>4){
            $("#allprice").val(($("#allprice").val()).substr(0,4));
        }
    }
    if($("#allprice").val()){
        //var a=$("#allprice").val().toString();
        //var b= a.substr(0,1);
        $("#allprice").val(parseFloat($("#allprice").val()));
        if($("#allprice").val().length>4){
            $("#allprice").val(($("#allprice").val()).substr(0,4));
        }
    }
});
//展示大图片------------------------------------------------
var winscrolltop;
var imghash={};//保存服务器返回的图片地址 “images.localId[i]”：imgurl
var delimgid="";//要删除的图片的Id
//展示大图
function showbigimg(e){
    winscrolltop=$(window).scrollTop();
    //console.log(winscrolltop);
    $("#page_wrapper").css("display","none");
    $("#showimg").attr("src", imgurl+e.dataset.img);//大图片的地址 和 Id 相同
    $("#digimgplace").css("display","block");
    var bigheight=$("#digimgplace").height();
    var imgheight=$("#showimg").height();
    if(bigheight>imgheight){
        $("#showimg").css("marginTop",(bigheight-imgheight)/2);
    }
    delimgid=e.dataset.img;//地址 和 Id 相同
}
//删除大图
$("#delthisimgbtn").click(function(e){
    imghash[delimgid]="";//清除对应ID 保存的服务器图片地址
    //页面中删掉图片
    var imgbox=document.getElementsByClassName("mainshowimgbox");
    for(var i= 0,r=imgbox.length;i<r;i++){
        if(imgbox[i].dataset.img==delimgid){
            //$imgbox=$(imgbox[i].dataset.img);
            $(".mainshowimgbox")[i].remove();
        }
    }
    $(".modifier.image").css("display","inlineBlock");
    $("#page_wrapper").css("display","block");
    $("#digimgplace").css("display","none");
});
//关闭地图区域
$("#digimgplace").click(function(e){
    if(e.id!="delthisimgbtn"){
        $("#page_wrapper").css("display","block");
        $("#digimgplace").css("display","none");
        if(winscrolltop>0){
            //console.log(winscrolltop);
            $(window).scrollTop(winscrolltop);
        }
    }
});
//最高金额页面返回
$("#pricepagebackbtn").click(function(){
    $("#pricepage").css("display","none");
    $("#outbox1").css("display","block");
});
//微信部分==========================================
$.ajax({
    type:"GET",
    url:"GetSign.ashx?p=weixin/sendexpg.html",
    success:function(data){
        timestampone=data.timestamp;
        nonceStrone=data.nonceStr;
        signatureone=data.signature;
        wx.config({
            debug:false,
            appId: 'wx658c34793ecfd9f9',
            timestamp:timestampone, //时间戳
            nonceStr:nonceStrone,  //随机字符串
            signature:signatureone,  //SHA1编码
            jsApiList: [
                // 所有要调用的 API 都要加到这个列表中
                "chooseImage","uploadImage","previewImage","downloadImage"
            ]
        });
    }
})
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////主页面操作////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var bodyplace=document.getElementsByClassName("bodyplace")[0];//主页面
var gaojilist=document.getElementsByClassName("gaojilist")[0];//高级页面
var inputbox1=document.querySelector("#inputbox1 div");//主页面确定按钮
var gjabtnok=document.querySelector("#gjabtnok");//高级页面确定按钮
var inputbox3=document.querySelector("#hyabtnok");//行业页面确定按钮
//点击后退
$("#maingobackbtn").click(function(){
    var conf=confirm("您的数据不会被保存，确定退出吗");
    if(conf===true){
        history.go(-1);
    }
});
//        输入框
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
function ResizeTextarea(a,row){
    if(!a){return}
    if(!row)
        row=5;
    var b=a.value.split("\n");
    var c=is_ie?1:0;
    c+=b.length;
    var d=a.cols;
    if(d<=20){d=40}
    for(var e=0;e<b.length;e++){
        if(b[e].length>=d){
            c+=Math.ceil(b[e].length/d)
        }
    }
    c=Math.max(c,row);
    if(c!=a.rows){
        a.rows=c;
    }
}
//        弹出设置价格
var sendquesbtn=document.getElementsByClassName("sendquesbtn")[0];//提交问题按钮
var tishiwords=document.getElementById("tishiwords");
var modalbg=document.getElementsByClassName("modal_bg")[0];
var modal=document.getElementsByClassName("action_menu_container")[0];
var modal=document.getElementsByClassName("action_menu_container2")[0];
var cancel=document.getElementsByClassName("cancel");
var timer;
var keywordtitle="";//关键词生成的标题
function changeclass(){
    modalbg.className='modal_bg';
    modal.className='action_menu_container';
    clearTimeout();
    timer=null;
    changedisplay();
};
function changedisplay(){
    modalbg.style.display="none";
    modal.style.display="none";
};

//页面按钮控件
var imgbtn=document.querySelector(".modifier.image");//主页面图片按钮
var choiceimgplace=document.getElementsByClassName("choiceimgplace")[0];
var imgokbtn=document.querySelector(".imgokbtn");//图片页面确定按钮
var imgchoicefriend=document.getElementById("sd-imgchoicefriend");//图片选择好友区域
var hidename=document.getElementById("hidename");//陌生人不可见
var strangecansee=document.getElementById("strangecansee");//陌生人不可见
//问题相关按钮控件
var callfriend=$("#callfriend")[0];//提醒谁看
var imgs = [];//图片列表-------用于向服务器传递参数
//、、、、、、、、、、、、、、、、、、、、、、、、、、、、方法提前
//主页面添加图片-----------------------------------------
var height21=parseFloat(document.body.clientWidth)*0.21;
//console.log(height21);
var urlfrom=location.href;
$("#questionbody .modifier").height(height21+"px");
//选择推荐城市-------------------------------------------
function getlocationhash(e){
    //------------------------------------------
    var name=lacationhash[e.id].name;
    $("#location div:nth-child(2)").html(lacationhash[e.id].name);
    $("#firstchoice .name").html(name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#firstchoice img").css("display","block");
    $("#firstchoice").css("display","block");
    //------------------------------------------
    $(".myctywords").html(lacationhash[e.id].name);
    $(".myctywords").css("display","none");
    $("#firstchoice").css("display","block");
    //alert(lacationhash[e.id].name);
    $("#firstchoice .name").html(lacationhash[e.id].name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#showmap").css("display","none");//页面
    $("#firstchoice img").css("display","block");
    $("#nolocation img").css("display","none");//钩
    $("#shiname img").css("display","none");
    //添加地址
    if(e.dataset.lng){
        question.longitude= e.dataset.lng;
        question.latitude=e.dataset.lat;
    }
}
var lacationhash={};//保存所有推荐定位的hash
var choicel=[];//已经选择的定位
//选择“不显示城市”------------------------------------
$("#nolocation").click(function(){
    $("#location div:nth-child(2)").html("所在位置");
    $(".myctywords").css("display","none");
    $(".myctywords").html("");
    $("#firstchoice").css("display","none");
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","block");
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","none");
});
//选择省份----------------------------------------------
var shengshi;//市
$("#shiname").click(function(e){
    $("#location div:nth-child(2)").html(shengshi);
    $("#firstchoice").css("display","none");
    $(".myctywords").html(shengshi);
    $(".myctywords").css("display","none");
    choicel=null;
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","none");//钩
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","block");
});
//选地址返回-------------------------------------------
$("#mapgoback").click(function(){
    $("#showmap").css("display","none");//页面
});
//搜索城市----------------------------------------------
var pagenum=1;
function searchcity(pagenum){
    if($("#locationsearch input")[0].value){
        var searchword=$("#locationsearch input")[0].value;
        $("#nosearch").css("display","block");
        var map = new AMap.Map("mapplace", {
            resizeEnable: true
        });
        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 20,
                pageIndex: pagenum,
                city: shengshi, //城市
                map: map
            });
            //关键字查询
            placeSearch.search(searchword,function(status, result){
                var data=result.poiList.pois;
                $(data).each(function(){
                    $("#searclocation").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                    if(!lacationhash[$(this)[0].id]){
                        lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                    }
                });
                $("#locationlistplace").css("display","none");
                $("#otherlist").css("display","none");
                $("#searclocation").css("display","block");
            });
        });
    }
}
//取消搜索----------------------------------------------
$("#nosearch").click(function(){
    $("#searclocation div").remove();
    $("#nosearch").css("display","none");
    $("#locationlistplace").css("display","block");
    $("#otherlist").css("display","block");
    $("#searclocation").css("display","none");
});
//------------------------------------------------------
var pageindex=1;
var nowlocation;//当前位置
//window.onload=function(){
if(qtypenum){question.qtype=qtypenum};//2问题3经验
//加载好友列表----------------------------------------------
//获得好友列表
$.ajax({
    datatype:"json",
    type:"get",
    url:friendlisturl+id,
    success:function(d){
        //console.log("好友列表");
        //console.log(d);
        if(d.Data.length>0){
            //排序
            //friendarr= d.Data;
            friendarr= (d.Data).sort(compare);
            //function compare(property){
            //    return function(a,b){
            //        var value1 = pinyin.getCamelChars(a[property]);
            //        var value2 = pinyin.getCamelChars(b[property]);
            //        return value1.localeCompare(value2);
            //    }
            //}
            //friendarr.sort(compare("friendnick"));
            hasharr={};//判断字母是否存在
            for(var i=0;i<friendarr.length;i++){
                if(friendarr[i].friendnick){
                    friendarr[this.index]=i;
                    //如果昵称开头为汉字或英文字母
                    var key=Pinyin.getCamelChars(friendarr[i].friendnick[0]);
                    var headimg="<img src='img/af8.png' class='topic_photo_img'/>"
                    if(friendarr[i].headimg){
                        headimg="<img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/>";
                    }
                    if(key.match(/[a-z|A-Z]/)){
                        key=key.toLowerCase();
                        //console.log(key);
                        if(!hasharr[Pinyin.getCamelChars(friendarr[i].friendnick[0])]){
                            hasharr[Pinyin.getCamelChars(friendarr[i].friendnick[0])]=i;
                        }
                        $("#maina").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                        $("#aa").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                    }else{
                        $("#mainjinghao").css("display","block");
                        $("#mainjinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                        $("#jinghao").css("display","block");
                        $("#jinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                    };
                }
            }
            //console.log(hasharr);
            for(var key in hasharr){
                key=key.toLowerCase();
                $("#sd-imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
                $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");

                $("#imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
                $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");
            };
        }
    }
});
//右侧导航条点击跳转
//字母键
var englishbtn1=document.querySelectorAll(".rightnav1 div.zmbtn");//导航条跳转
var tonum1=0;
for(var en1=0;en1<englishbtn1.length;en1++){
    englishbtn1[en1].onclick=function(e){
        console.log("点击的是："+e.target.innerHTML);
        if(document.querySelector(".section_header.section_header_gray."+(e.target.innerHTML).toLowerCase())){
            console.log("进行跳转");
            var engtitlenum=parseFloat(hasharr[e.target.innerHTML]);
            var divnum=parseFloat(document.querySelector(".section_header.section_header_gray."+(e.target.innerHTML).toLowerCase()).dataset.num);
            var divheight=$(".friends").eq(0).height();
            var titleheight=$("div.section_header.section_header_gray").eq(0).height();
            heightdiv=titleheight*engtitlenum+divnum*divheight;
            $(window).scrollTop(0);
            $(window).scrollTop(heightdiv);
            console.log("页面跳转操作")
        }
    };
}
//定位 城市-------------------------------------------------
//周边推荐--------------------------------------------------
function otherlocal(position,shiname,pageindex){
    var map = new AMap.Map("mapplace", {
        resizeEnable: true
    });
    AMap.service(["AMap.PlaceSearch"], function() {
        var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
            pageSize: 20,
            pageIndex:pageindex,
            city: shiname, //城市
            map: map
            //panel: "otherlist"
        });
        var cpoint = position; //中心点坐标
        placeSearch.searchNearBy('', cpoint, 200, function(status, result) {
            var data=result.poiList.pois;
            $(data).each(function(){
                $("#otherlist").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                if(!lacationhash[$(this)[0].id]){
                    lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                }
                //选择周边推荐----------------
            });

        });
    });
}
//调用地图
function startmap(){
    //高德地图--------------------------------------------------
    var map, geolocation;
//加载地图，调用浏览器定位服务
    map = new AMap.Map('mapplace', {
        resizeEnable: true
    });
    map.plugin('AMap.Geolocation', function() {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            noIpLocate:0,
            GeoLocationFirst:false,//默认为false，设置为true的时候可以调整PC端为优先使用浏览器定位，失败后使用IP定位
            convert: true,         //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
            timeout: 100000,          //超过100秒后停止定位，默认：无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            buttonPosition:'RB'
        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
        AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
    });
//解析定位结果
    function onComplete(data) {
        var shiname=data.formattedAddress.split("省")[1].split("市")[0]+"市";
        shengshi=shiname;
        nowlocation=data.position;
        $("#shiname div").html(shiname);
        otherlocal(data.position,shiname,pageindex);
    }
//解析定位错误信息
    function onError(data) {
        //document.getElementById('tip').innerHTML = '定位失败';
    }
}
startmap();
$("#location").click(function(){
    $("#locationlistplace").css("display","block");//搜索影响
    $("#otherlist").css("display","block");
    $("#showmap").css("display","block");//展开页面
});
$("#showmap").scroll(function(){
    var mainheight=$(".home_feed").height();
    var windowheight=$(window).height();
    var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+5;
    //console.log();
    if(chajuli<cz){
        if($("#searclocation").css("display")==="none"){
            pageindex++;
            otherlocal(nowlocation,shengshi,pageindex);
        }
        else{
            pagenum++;
            searchcity(pagenum);
        }
    }
});
//匿名发布--------------------------------------------------
hidename.onclick=function(){
    if(question.ishidename ===0){
        question.ishidename = 1;
        atmeIsHideName=1;
        $("#hidename div.changephotobox img").attr("src","img/hook01.png")
    }else if(question.ishidename ===1){
        question.ishidename =0;
        atmeIsHideName=0;
        $("#hidename div.changephotobox img").attr("src","img/hook-no.png")
    }
};
//陌生人不可见（问题经验）-----------------------------------
strangecansee.onclick=function(){
    if(question.isstrangersee ===1){
        question.isstrangersee =0;
        $("#strangecansee div.changephotobox img").attr("src","img/hook01.png")
    }else if(question.isstrangersee ===0){
        question.isstrangersee =1;
        $("#strangecansee div.changephotobox img").attr("src","img/hook-no.png")
    }
};
//上传图片--------------------------------------------------
var images = {
    localId: [],
    serverId: []
};
var sendlocalIds;
imgbtn.onclick=function(){
    //微信部分==========================================
    var imgnum=9;//选择图片个数
    if(document.getElementsByClassName("mainshowimgbox")&&document.getElementsByClassName("mainshowimgbox").length>0){
        imgnum=9-document.getElementsByClassName("mainshowimgbox").length;
    }
    wx.chooseImage({
        count: imgnum, // 默认9
        sizeType:['compressed'],
        success: function(res) {
            var cameraimg;
            images.localId = res.localIds;
            //alert("本地ID："+res.localIds);
            //如果只选了一张照片 看成拍照设置cameraimg
            if( res.localIds.length==1){
                cameraimg= res.localIds;
                //alert("拍照的图片地址："+cameraimg);
            }
            //alert('已选择 ' + res.localIds.length + ' 张图片');
            if (images.localId.length == 0) {
                alert('请先使用 chooseImage 接口选择图片');
                return;
            }else{
                //如果不是拍照
                //if(!cameraimg){
                //    var divheight=parseFloat(window.innerWidth)*0.21;
                //    for(var r=0;r<images.localId.length;r++){
                //        $("<div class='mainshowimgbox' style='height:"+divheight+"px;overflow:hidden;' onclick='showbigimg(this)'  data-imgurl='"+images.localId[r]+"' data-img='"+images.localId[r]+"'><img src='"+images.localId[r]+"'></div>").insertBefore("#questionbody .modifier.image");
                //    }
                //}
            }
            var divheight=parseFloat(window.innerWidth)*0.21;
            var i = 0, length = images.localId.length;
            images.serverId = [];
            function upload(){
                wx.uploadImage({
                    localId: images.localId[i],
                    isShowProgressTips: 0, // 默认为1，显示进度提示
                    success: function(res) {
                        var locaimgurl=images.localId[i];
                        i++;
                        images.serverId.push(res.serverId);

                        //$("body").append("<img style='width:200px;height:200px;position:fixed;z-index:99999;top:0;right:0;vertical-align: inherit;' src='http://42.62.66.198:8003/Images/tF3JR8j4T2K588oW6XWpjTMp3Waqe9D0VUxSdiE3fpJ0ZW_ZCXgSyC64T9ZmF0wx.jpg'/>");
                        //请求服务器下载图片
                        $.ajax({
                            type:"get",
                            url:wxgetimgurl+res.serverId,
                            success:function(img){
                                var imgurlword;
                                imgurlword=img.replace("C:\\","");
                                alert(cameraimg);
                                if(cameraimg&&cameraimg.length==1){ //只选了一张图片 看成拍照
                                    //$(".modifier.image").css("background","url('"+imgurl+imgurlword+"')");
                                    $("<div class='mainshowimgbox' style='height:"+divheight+"px;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+cameraimg+"' data-img='"+imgurlword+"'><img src='"+cameraimg+"'></div>").insertBefore("#questionbody .modifier.image");

                                    imghash[res.serverId]=img.replace("C:\\","");
                                }else{
                                    $("<div class='mainshowimgbox' style='height:"+divheight+"px;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+cameraimg+"' data-img='"+imgurlword+"'><img src='"+images.localId[i-1]+"'></div>").insertBefore("#questionbody .modifier.image");
                                    imghash[images.localId[i]]=img.replace("C:\\","");
                                }
                                //判断图片个数 9个隐藏按钮
                                if(document.getElementsByClassName("mainshowimgbox")&&document.getElementsByClassName("mainshowimgbox").length==9){
                                    $(".modifier.image").css("display","none");
                                }
                                //若果没上传好就继续
                                if (i < length) {
                                    upload();
                                }
                            }
                        });
                    },
                    fail: function(res) {
                        alert("图片上传失败了");
                        //alert(JSON.stringify(res));
                    }
                });
            }
            upload();
        }
    });
};
$("#addimgfilebtn").height(($(window).width()-30)*0.23);
//金额加减按钮操作----------------------------------------
//金额加减按钮操作
$("#leftjianbtn").click(function(){
    var num=$("#price").val();
    num=parseFloat(num);
    if(!num||num<=1){
        $("#price").val(1);
        $("#leftjianbtn").css("backgroundImage","url('img/reduce_light.png')");
        $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
    }else{
        if(num===5){
            $("#price").val(1);
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_light.png')");
            $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
        }else if(num>=9){
            $("#price").val(5);
            $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
        }else{
            --num;
            $("#price").val(num);
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
            $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
        }
    }
});
$("#rightjiabtn").click(function(){
    var num=$("#price").val();
    num=parseFloat(num);
    if(num>=9){
        $("#price").val("9");
        num=9;
        $("#rightjiabtn").css("backgroundImage","url('img/add_light.png')");
        $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')")
    }else{
        if(num===1||!num){
            $("#price").val("5");
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')")
        }else if(num===5){
            $("#price").val("9");
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
            $("#rightjiabtn").css("backgroundImage","url('img/add_light.png')")
        }else{
            ++num;
            $("#price").val(num);
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
            $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
        }
    }
});
//监听输入框数字变化取消提醒文字
$("#unitprice").on("input propertychange",function(){
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
});
$("#allprice").on("input propertychange",function(){
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
});
$("#allday").on("input propertychange",function(){
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
});
//问题经验提醒谁看@
callfriend.onclick=function(){
    bodyplace.style.display="none";
    imgchoicefriend.style.display="block";//与图片共用一个好友列表
    $(window).scrollTop(0);
    sendfriend=1;
    callfrienfname=[];
};
//提醒谁看
imgchoicedFDokbtn.onclick=function(){
    imgchoicefriend.style.display="none";
    bodyplace.style.display="block";
    //console.log("提醒谁看方法");
    var choicefriendlist=$("#sd-imgchoicefriend .addchatpeoplebtn");//所有好友列表 单选按钮
    persons = [];
    for(var f=0;f<choicefriendlist.length;f++){
        //console.log("提醒谁看方法for循环");
        if(choicefriendlist[f].checked==true){
            persons.push(choicefriendlist[f].parentNode.id);
            var childlist=choicefriendlist[f].parentNode.childNodes;
            for(var i=0;i<childlist.length;i++){
                if(childlist[i].className==="innerplace tc_text"){//wentibufen ///////////////////////////////
                    callfrienfname.push(childlist[i].innerHTML);
                    console.log(callfrienfname);
                }
            }
        }
    }
    if($("#callfriendwords span")){
        $("#callfriendwords span").remove();
    }
    if(callfrienfname.length!=0){
        if(callfrienfname.length>3){
            $("#callfriendwords").append("<span>"+callfrienfname[0]+","+callfrienfname[1]+","+callfrienfname[2]+"等"+callfrienfname.length+"人"+"</span>")
        }else{
            for(var ii=0;ii<callfrienfname.length;ii++){
                $("#callfriendwords").append("<span>"+callfrienfname[ii]+"</span>")
            }
        }
    }
};
//提醒谁看页面关闭
$("#friendlistgoback").click(function(){
    $("#sd-imgchoicefriend").css("display","none");
    $("#page_wrapper").css("display","block");
});
//切换经验类型 先判断经验个数
var havesendexpnum=0;
$.ajax({
    type:"get",
    url:"https://www.pulu.com/webapi/api/puluquestion/GetExpCountByUserId?userId="+id,
    datatype:"json",
    success:function(data){
        //console.log(data.Data);
        havesendexpnum=data.Data;
        //havesendexpnum=2;
    }
});
$("#norexpinput").click(function(){
    $(".heiexpinput").css("display","none");
    $(".norexpinput").css("display","block");
    $("#errorword").css("display","none");
    $("#cannotsend").css("display","none");
    $("#oksenditbtn").css("display","block");
    $("#norexpword").css("display","block");
    if($("#norexpinput").prop("checked")){console.log("norexpinput checked")}
});
$("#hexpinput").click(function(){
    if(havesendexpnum>2){
        $(".heiexpinput").css("display","block");
        $(".norexpinput").css("display","none");
        $("#errorword").css("display","block");
        $("#norexpword").css("display","none");
        if($("#hexpinput").prop("checked")){console.log("hexpinput checked")}
    }
    else{
        $(".norexpinput").css("display","none");
        $("#norexpword").css("display","none");
        $("#oksenditbtn").css("display","none");
        $("#cannotsend").css("display","block");
    }
});
//类别筛选
question.chikui= 0, //吃亏经验
    question.huasuan= 0, //划算
    question.xinqi= 0, //新奇
    question.qita= 0, //其他
    question.tuijiandy= 0, // 推荐电影
    question.tuijianfd= 0, //推荐饭店
    question.youwan= 0, //游玩
    question.shu= 0; //书
var chickednum=0; //选取个数

if($.cookie("expType")){
    var et=$.cookie("expType");
    $("#"+et).attr("checked",true);
    switch(et) {
        case "chikui":question.chikui=1;break;
        case "huasuan":question.huasuan=1;break;
        case "xinqi":question.xinqi=1;break;
        case "qita":question.qita=1;break;
        case "tuijiandy":question.tuijiandy=1;break;
        case "tuijianfd":question.tuijianfd=1;break;
        case "youwan":question.youwan=1;break;
        case "shu":question.shu=1;break;
        case "nearlyexp":question.youwan=1;break;//附近
        case "rensheng":question.shu=1;break;
    }
    chickednum=1;
}

$(".td input").on("change",function(e){
    if($(e.target).prop("checked")){
        if(chickednum>=3){
            $(e.target).attr("checked",false);
        }
        else{
            chickednum++;
            switch(e.target.id) {
                case "chikui":question.chikui=1;break;
                case "huasuan":question.huasuan=1;break;
                case "xinqi":question.xinqi=1;break;
                case "qita":question.qita=1;break;
                case "tuijiandy":question.tuijiandy=1;break;
                case "tuijianfd":question.tuijianfd=1;break;
                case "youwan":question.youwan=1;break;
                case "shu":question.shu=1;break;
                case "nearlyexp":
                    question.fujinjy=1;
                    $("#locationbox").css("display","block");
                    break;
                case "rensheng":question.rensty=1;break;
            }
        }
    }
    else{
        chickednum--;
        switch(e.target.id) {
            case "chikui":question.chikui=0;break;
            case "huasuan":question.huasuan=0;break;
            case "xinqi":question.xinqi=0;break;
            case "qita":question.qita=0;break;
            case "tuijiandy":question.tuijiandy=0;break;
            case "tuijianfd":question.tuijianfd=0;break;
            case "youwan":question.youwan=0;break;
            case "shu":question.shu=0;break;
            case "nearlyexp":
                question.fujinjy=0;
                $("#locationbox").css("display","none");
                question.longitude="";
                question.latitude="";
                //同不选择城市
                $("#location div:nth-child(2)").html("所在位置");
                $(".myctywords").css("display","none");
                $(".myctywords").html("");
                $("#firstchoice").css("display","none");
                $("#showmap").css("display","none");//页面
                $("#nolocation img").css("display","block");
                $("#firstchoice img").css("display","none");
                $("#shiname img").css("display","none");
                break;
            case "rensheng":question.rensty=0;break;
        }
    }
});
//设置价格按钮进行提价操作    提交所有信息
//最后操作获取其他参数 发送请求====================================================================
//发高额经验
function sendh(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName){
    if(parseFloat($("#unitprice").val())<1){
        $("#errorword span").css("display","block");
        //$("#errorword>ul").css("display","none");
        $("#errorword span").html("金额不能低于1元");
    }else if(parseFloat($("#unitprice").val())>999){
        $("#errorword span").css("display","block");
        //$("#errorword>ul").css("display","none");
        $("#errorword span").html("金额不能超过999元");
    }else{
        if(!/^\d+$/g.test($("#allday").val())){ //------------------
            $("#errorword span").css("display","block");
            //$("#errorword>ul").css("display","none");
            $("#errorword span").html("天数不能为空");
        }else{
            if(parseFloat($("#allday").val())>365){
                $("#errorword span").css("display","block");
                //$("#errorword>ul").css("display","none");
                $("#errorword span").html("天数不能超过365天");
            }else if(parseFloat($("#allday").val())<1){
                $("#errorword span").css("display","block");
                //$("#errorword>ul").css("display","none");
                $("#errorword span").html("天数必须在1-365之间");
            }else{
                if(!/^\d+$/g.test($("#allprice").val())){
                    $("#errorword span").css("display","block");
                    //$("#errorword>ul").css("display","none");
                    $("#errorword span").html("总收入不能为空");
                }else if(parseFloat($("#allprice").val())>9999){
                    $("#errorword span").css("display","block");
                    //$("#errorword>ul").css("display","none");
                    $("#errorword span").html("总收入不能超过9999元");
                }
                else{
                    if(parseFloat($("#allprice").val())<parseFloat($("#unitprice").val())){ //------------------
                        $("#errorword span").css("display","block");
                        //$("#errorword>ul").css("display","none");
                        $("#errorword span").html("预期总收入不能小于单价");
                    }else{
                        //共用参数
                        //......
                        //高额参数
                        if(document.getElementById("unitprice").value.match(/^[0-9]+$/g)){
                            question.score=parseFloat(document.getElementById("unitprice").value)*100;//分数
                            question.unitamount=parseFloat(document.getElementById("unitprice").value)*100;//分数
                            question.isexphigh=1;
                            question.totalamount=parseFloat(document.getElementById("allprice").value)*100;//总额
                            question.expireDay=parseFloat(document.getElementById("allday").value);//期限
                            //可以提交数据
                            sendn(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName);
                        }
                    }
                }
            }
        }
    }
}
//发普通经验
function sendn(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName){
    var senddata={"atmeuserId":callerid, "pulu_question": question, "persons": persons, "imgs": imgs, "jobtypes": jobtypes, "hobbytypes": hobbytypes, "qSeePlist": sendcanseelist,"atmeIsHideName":atmeIsHideName};
    var sendurl="https://www.pulu.com/webapi/api/puluquestion/AddPulu_question_e";
    if(question.qtype==2){
        senddata={"atmeuserId":callerid, "pulu_question": question, "persons": persons, "imgs": imgs, "jobtypes": jobtypes, "hobbytypes": hobbytypes, "qSeePlist": sendcanseelist};
        sendurl="https://www.pulu.com/webapi/api/puluquestion/AddPulu_question_q";
    }
    if(question.qtype==2&&parseFloat(document.getElementById("price").value)>userallmoney){
        alert("您的余额不足，请重新设置问题的悬赏金额");
        $("#price").val("");
    }else{
        //上传提示提示框
        $("#sendinfo").css("display","block");
        $(".paynoteplace").css("display","none");
        $.ajax({
            //提交数据的类型 POST GET
            type: "post",
            //提交的网址
            url: sendurl,
            //提交的数据
            data:senddata ,
            //返回数据的格式
            datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
            //成功返回之后调用的函数
            success: function (data) {
                //console.log(data);
                if(data.Code=="TRUE"){
                    //location.href="searchdetail.html?id="+id;
                    $("#sendinfo").css("display","none");
                    $.cookie("expkeyword","");
                    $.cookie("sendque","");
                    $.cookie("expType","");
                    if(question.qtype==2){location.href="https://www.pulu.com/weixin/questionlisttw.html";}
                    else if(question.qtype==3){location.href="https://www.pulu.com/weixin/questionlistjy.html";}
                }else{
                    $("#sendinfo").css("display","none");
                    alert("关键词未在文中出现，请修改关键词");
                };
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                if(XMLHttpRequest.status==500){
                    $("#sendinfo").css("display","none");
                    $.cookie("expkeyword","");
                    $.cookie("sendque","");
                    $.cookie("expType","");
                    if(question.qtype==2){location.href="https://www.pulu.com/weixin/questionlisttw.html";}
                    else if(question.qtype==3){location.href="https://www.pulu.com/weixin/questionlistjy.html";}
                }
                else{
                    alert("发送失败，请稍后再试");
                }
            }
        });
    }
}
// 发布按钮
sendquesbtn.onclick=function(){
    if($("#choiceque").attr("class")=="active"){
        question.qtype=2;
    }else if($("#choiceexp").attr("class")=="active"){
        question.qtype=3;
    }
    //经验要有关键词
    if($("#contentword").val().trim().length<10&&(question.qtype)==3){
        alert("字数有点少，再加点吧，至少10字哦");
    }else if(document.getElementById("keywordinput").value&&!document.getElementById("keywordinput").value.match(/^\s+$/g)){
        if(question.qtype==3){
            var keyword=document.getElementById("keywordinput").value;
            var outbox1=document.getElementById("outbox1");
            $("#pricepage").css("display","block");
            $("#outbox1").css("display","none");
            keywordtitle=document.getElementById("keywordinput").value;
            $(window).scrollTop(0);
        }
        //
        else if(question.qtype==2){
            $(".paynoteplace").css("display","block");
        }
    }else{
        $("#nokeywordalert").css("display","block");
    }
};
$("#closealertbtn").click(function(){
    $("#nokeywordalert").css("display","none");
});
//问题取消发布
$("#donotsendbtn").click(function(){
    $(".paynoteplace").css("display","none");
});
//发经验
$("#oksenditbtn").click(function(){
    console.log(question.qtype);
    //普通高额共用参数
    //图片
    if(document.getElementsByClassName("mainshowimgbox")[0]){
        imgs = [];
        //console.log("有图片",document.getElementsByClassName("mainshowimgbox"));
        //从数组中获取图片
        var imgbox=document.getElementsByClassName("mainshowimgbox");
        for(var i= 0,len=imgbox.length;i<len;i++){
            var img={};
            img.plist ="";
            if(!/Images\//.test(imgbox[i].dataset.img)){

                img.name="Images/"+imgbox[i].dataset.img+".jpg";
            }else{
                img.name=imgbox[i].dataset.img;
            }

            imgs.push(img);
        }
    }else{
        //console.log("没有图");
        imgs="[]";
    }
    question.content = document.getElementById("contentword").value;
    question.questionUserId = id;//发布人的id
    question.status ="1";
    if($(".myctywords span")){
        question.pululocation = $(".myctywords").html();
    }
    //兴趣
    var hobbytypes = [];
    var userhobby=document.querySelectorAll(".kindword.xingquwords>span");
    if(userhobby){
        for(var h=0;h<userhobby.length;h++){
            var t={};
            t.id=userhobby[h].id;
            t.name=userhobby[h].innerHTML;
            hobbytypes.push(t);
        }
    }
    //行业
    var jobtypes = [];
    var userjob=document.querySelectorAll(".kindword.hangyewords>span");
    if(userjob){
        for(var j=0;j<userjob.length;j++){
            var t1={};
            t1.id=userjob[j].id;
            t1.name=userjob[j].innerHTML;
            jobtypes.push(t1);
        }
    }
    var sendcanseelist = [];//可见人的id列表
    if(question.iswhocansee ===1){
        var seelabellistimg=document.querySelectorAll("#someseelabel .labelbox .labellist .labelbtnimg");
        for(var ii=0;ii<seelabellistimg.length;ii++){
            if(seelabellistimg[ii].src.match("hook01")){
                var num=seelabellistimg[ii].dataset.i;
                for(var iii=0;iii<labeldata[num].userList.length;iii++ ){
                    sendcanseelist.push(labeldata[num].userList[iii].userId);
                }
            }
        }
    }
    else if(question.isforbidwhosee ===1){
        var notlabellistimg=document.querySelectorAll("#cannotseelabel .labelbox .labellist .labelbtnimg");
        for(var rr=0;rr<notlabellistimg.length;rr++){
            if(notlabellistimg[rr].src.match("hook01")){
                var num1=notlabellistimg[rr].dataset.i;
                for(var rrr=0;rrr<labeldata[num1].userList.length;rrr++ ){
                    sendcanseelist.push(labeldata[num1].userList[rrr].userId)
                }
            }
        }
    }
    else if(question.iswhocansee ===0&&question.isforbidwhosee ===0){
        sendcanseelist=[];
    }
    //发送问题的关键字
    question.keywords=$("#keywordinput").val();
    console.log(sendcanseelist);
    var callerid="";
    if(persons.length>0){
        callerid=id;
    }

    //判断输入数字是否符合要求
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
    var urlregex = new RegExp("^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~])+");
    if(urlregex.test(location.href))
    {question.relateUrl=$("#urlword").val()};
    //发高额经验
    if($("#hexpinput").prop("checked")){
        if(!/^\d+$/g.test($("#unitprice").val())) {
            $("#errorword span").css("display","block");
            //$("#errorword>ul").css("display","none");
            $("#errorword span").html("金额不能为空");
        }else {
            $("#sendinfop").html("正在发布，请耐心等待..");
            sendh(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName)
        }
    }
    //发普通
    if($("#norexpinput").prop("checked")){
        question.score=30;//分数
        $("#sendinfop").html("正在发布经验，请耐心等待系统智能审核..");
        sendn(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName)
    }
});
//};

//发问题
$("#sendquebtn").click(function(){
    //图片
    if(document.getElementsByClassName("mainshowimgbox")[0]){
        imgs = [];
        //从数组中获取图片
        var imgbox=document.getElementsByClassName("mainshowimgbox");
        for(var i= 0,len=imgbox.length;i<len;i++){
            var img={};
            img.plist ="";
            if(!/Images\//.test(imgbox[i].dataset.img)){img.name="Images/"+imgbox[i].dataset.img+".jpg";}
            else{img.name=imgbox[i].dataset.img;}
            imgs.push(img);
        }
    }else{imgs="[]";}
    question.content = document.getElementById("contentword").value;
    question.questionUserId = id;//发布人的id
    question.status ="1";
    if($(".myctywords span")){question.pululocation = $(".myctywords").html();}
    //兴趣
    var hobbytypes = [];
    //行业
    var jobtypes = [];
    //可见人的id列表
    var sendcanseelist = [];
    if(question.iswhocansee ===1){
        var seelabellistimg=document.querySelectorAll("#someseelabel .labelbox .labellist .labelbtnimg");
        for(var ii=0;ii<seelabellistimg.length;ii++){
            if(seelabellistimg[ii].src.match("hook01")){
                var num=seelabellistimg[ii].dataset.i;
                for(var iii=0;iii<labeldata[num].userList.length;iii++ ){
                    sendcanseelist.push(labeldata[num].userList[iii].userId);
                }
            }
        }
    }
    else if(question.isforbidwhosee ===1){
        var notlabellistimg=document.querySelectorAll("#cannotseelabel .labelbox .labellist .labelbtnimg");
        for(var rr=0;rr<notlabellistimg.length;rr++){
            if(notlabellistimg[rr].src.match("hook01")){
                var num1=notlabellistimg[rr].dataset.i;
                for(var rrr=0;rrr<labeldata[num1].userList.length;rrr++ ){
                    sendcanseelist.push(labeldata[num1].userList[rrr].userId)
                }
            }
        }
    }
    else if(question.iswhocansee ===0&&question.isforbidwhosee ===0){sendcanseelist=[];}
    //发送问题的关键字
    question.keywords=$("#keywordinput").val();
    var callerid="";
    if(persons.length>0){callerid=id;}
    //判断输入数字是否符合要求
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
    //普通经验 问题共用方法
    if(!document.getElementById("price").value){
        alert("问题金额不能低于1元");
    }
    else{
        question.score=parseFloat(document.getElementById("price").value)*100;//分数
        $("#sendinfop").html("正在发布，请耐心等待..");
        sendn(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName)
    }
});
//监听输入框
$("#csearchinput1").bind('input propertychange',function(){
    if(!$("#csearchinput1").val()){
        $("#aa").css("display","block");
        $("#a1").css("display","none");
    }
});
$("#price").on('input propertychange',function(){
    if(!/^[0-9]+$/.test($("#price").val())||$("#price").val()==0){
        $("#price").val("");
    }
});
//取消发布
//$("#donotsendbtn").click(function(){
//    $(".modal_bg.modal_bg2").css("display","none");
//    $(".action_menu_container2").css("display","none");
//})
//键盘回车
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){
        //城市搜索
        $("#searclocation div").remove();
        searchcity(pagenum);
    }
};
//绑定输入
$('#locationsearch input').bind('input propertychange', function() {
    //城市搜索
    $("#searclocation div").remove();
    searchcity(pagenum);
});
$("#gaojibtn").click(function(){
    if($("#gaojilistbox").css("display")=="block"){
        $("#gaojilistbox").css("display","none");
        //匿名发布
        //$("#hidenamebox").css("display","none");
        //定位
        //$("#locationbox").css("display","none");
        //箭头
        $("#gaojiimg").attr("src","img/darr01.png");
    }else{
        $("#gaojilistbox").css("display","block");
        //匿名发布
        //$("#hidenamebox").css("display","block");
        //定位
        $("#locationbox").css("display","block");
        //箭头
        $("#gaojiimg").attr("src","img/uarr01.png");
    }
});
//详细规则区域
$("#modaltishiwords").click(function(){
    $("#detailrule").css("display","block");
    $(".paynoteplace").css("display","none");
});
$("#iknow").click(function(){
    $("#detailrule").css("display","none");
    $(".paynoteplace").css("display","block");
});
